#!/bin/sh -efu

[ "${GLOBAL_BOOTLOADER-}" = grubpcboot ] || exit 0

cd /tmp
rm -fr syslinux
mkdir syslinux
cp /usr/lib/syslinux/hdt.c32 syslinux/
mv "$WORKDIR"/syslinux/pci.ids syslinux/

cat > syslinux/syslinux.cfg << EOF
default hdt
label hdt
  menu label ^Hardware info
  com32 hdt.c32
  append quiet
EOF

# floppy disk 720 KiB
mkdir -p "$WORKDIR"/boot
dd if=/dev/zero of="$WORKDIR"/boot/hdt.img bs=512 count="1440"
mkfs.fat -n HDT -F 12 "$WORKDIR"/boot/hdt.img
mcopy -i "$WORKDIR"/boot/hdt.img -s syslinux ::

# clean /tmp
rm -r syslinux

#dd if=/usr/lib/syslinux/ldlinux.bss of=boot/hdt.img conv=notrunc
syslinux -d /syslinux --install "$WORKDIR"/boot/hdt.img

cp /usr/lib/syslinux/memdisk "$WORKDIR"/boot
